<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Validate;

/**
 * 会员接口
 */
class Apply extends Api
{

    protected $noNeedLogin = ['login', 'register'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 会员中心
     */
    public function index()
    {
        $this->success('', ['welcome' => $this->auth->nickname]);
    }

    /**
     * 会员登录
     * 
     * @param string $account 账号
     * @param string $password 密码
     */
    public function login()
    {
        $account = $this->request->request('account');
        $password = $this->request->request('password');
        if (!$account || !$password)
        {
            $this->error(__('Invalid parameters'));
        }

        $_Apply = model('apply');

        // 获取用户信息
        $Ret = $_Apply->where(['tel'=>$account])->find();

        if ($Ret)
        {
            if($Ret->password == md5($password)){
                $this->success(__('Logged in successful'), ['tel'=>$account]);
            }else{
                $this->error('密码错误');
            }
        }
        else
        {
            $this->error('用户不存在');
        }
    }




    /**
     * 注销登录
     */
    public function logout()
    {
        $this->success(__('Logout successful'));
    }

}
